home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3462 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: news.accessone.com!news
  2. From: bokr@accessone.com (Bengt Richter)
  3. Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
  4. Subject: Re: C++ with Zapp vs. Delphi
  5. Date: Wed, 24 Jan 1996 05:56:02 GMT
  6. Organization: -
  7. Message-ID: <4e4hrl$oqc@news.accessone.com>
  8. References: <4coar6$d4n@sun4.bham.ac.uk> <4coip7$69s@news1.usa.pipeline.com> <DBk8wg2yqjbB083yn@iaccess.za> <4d7pmb$48c8@tigger.cc.uic.edu> <4dk38h$gdr@merlin.delphi.com> <4dksp1$3d6c@tigger.cc.uic.edu> <30fe666e.3349285@130.15.126.54> <4durk2$2r54@tigger.cc.uic.edu> <31038877.2364473@130.15.126.54>
  9. NNTP-Posting-Host: bokr.accessone.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. dmurdoch@mast.queensu.ca (Duncan Murdoch) wrote:
  13.  
  14. >olczyk@sunphy1 (Constantin Rasinariu) wrote:
  15.  
  16. >>Duncan Murdoch (dmurdoch@mast.queensu.ca) wrote:
  17.  
  18. [...]
  19. >  What I want
  20. >is to have two lists (say AlphaList and NumericList) and put
  21. >references to the same object in both lists.  The first would end up
  22. >sorted alphabetically, the second numerically.
  23.  
  24. >Duncan
  25.  
  26. PMJI from left field, but TStringlist has a Quicksort method which
  27. seems like it could be extracted and re-adapted to accept an external
  28. compare function (like C examples I've seen). It already operates with
  29. the array of object references in a TList, so it wouldn't seem like
  30. too big a deal to do just what you say. E.g., create one TList each
  31. for the AlphaList and NumericList, and put references to the same
  32. objects in both, then use the same quicksort on both, but passing
  33. alpha and numeric comparison functions respectively. Only the
  34. comparison functions need to know what kind of objects they are
  35. operating on. (Let unspecialized lists stick to knowing about their
  36. own structure). TList has an exchange method that can do the requisite
  37. swapping, (which is appropriate since it doesn't have to know what
  38. objects are being referred to).
  39. So you ought to be able to have a simple
  40.   QuickSort(ATList,AComparisonFcn);
  41. call to do the job, where AComparisonFcn , might point to
  42.  
  43.   AlphaCompareTxx(const Left:TObject; const Right:TObject):integer;
  44.   begin
  45.     Result:=AnsiCompareText(Txx(Left).MyString,Txx(Right).MyString);
  46.   end;
  47. or
  48.   NumericCompareTxx(const Left:TObject; const Right:TObject):integer;
  49.   begin
  50.     Result:= Txx(Left).MyInteger-Txx(Right).MyInteger;
  51.   end;
  52.  
  53. You could use (Left as Txx).My... to check type validity, at some
  54. speed cost. Or you could use the type info iself to make those items
  55. go to the beginning or end of the list, etc.
  56.  
  57. My 2 cents' worth. (Untested).
  58. Regards, Bengt Richter
  59.  
  60.  
  61.